//总的模块管理器，给各模块提供统一的接口
var NetService = require('./framework/netservice');
var HandlerService = require('./framework/handlerservice');
var ChannelService = require('./core/channelservice');
var BattleService = require('./core/battleservice');
var Player = require('./core/player');
var CARD_TYPE = require('./core/card').CARD_TYPE;

var g_ServerConfig = {
    cards :{
        "attack" :{prob:100,type:CARD_TYPE.ATTACK_CARD},
        "iron-force":{prob:10,type:CARD_TYPE.DEFENSE_BUFFER_CARD},
        "blade-master":{prob:10,type:CARD_TYPE.SPECAIL_ATTACK_CARD,params:{num:100,attack:100}},
    },
    combo:{
        "246":{type:CARD_TYPE.SPECAIL_ATTACK_CARD,params:{num:50,factor:1.2}},
        "184":{type:CARD_TYPE.HP_RECOVER_CARD,params:{hp:20}},
        "929":{type:CARD_TYPE.SPECAIL_ATTACK_CARD,params:{num:51,factor:1.2}},
    }
};

function App(){
    this.netService =  new NetService(this);
    this.handlerService = new HandlerService(this);
    this.channelService = new ChannelService(this);
    this.battleService = new BattleService(this);
    this.config = g_ServerConfig;
}

App.prototype.getPath = function(){
    return ".";
}

App.prototype.start = function(){
    this.netService.start();
    this.handlerService.start();
}

App.prototype.getNetService = function(){
    return this.netService;
};

App.prototype.getHandlerService = function(){
    return this.handlerService;
};

App.prototype.getChannelService = function(){
    return this.channelService;
};

App.prototype.getBattleService = function(){
    return this.battleService;
};

App.prototype.getConfig = function(){
    return this.config;
};
app = new App();
app.start();


Player.prototype.onDisconnect = function(){
    app.getChannelService().leaveAllChannel(this.id);
};